package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CheckGroupMapper extends BaseMapper<CheckGroup> {

    //查询检查组（分页查询）
    @Select("select * from t_checkitem tc,t_checkgroup_checkitem tcc where tcc.checkgroup_id = #{id} and tcc.checkitem_id = tc.id")
    List<CheckItem> findByGroupId(CheckGroup record);


    //添加检查组中的检查项
    @Insert("insert into t_checkgroup_checkitem values (#{id},#{checkitem_id})")
    void add(@Param("id") Integer id,@Param("checkitem_id") Integer checkitemId);

    //检查项数据回显
    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{id}")
    Integer[] findCheckItemIdsByCheckGroupId(@Param("id") Integer id);

    //删除中间表数据
    @Delete("delete  from t_checkgroup_checkitem where checkgroup_id=#{id}")
    void deleteCheckitemId(@Param("id")Integer id);

    //删除检查组
    @Delete("delete from t_checkgroup where id=#{id}")
    void deleteCheckGroupId(@Param("id")Integer id);
}
